/*    */ package scripting.lieDetector;
/*    */ 
/*    */ import configs.ServerConfig;
/*    */ import java.io.ByteArrayOutputStream;
/*    */ import java.io.File;
/*    */ import java.io.FileInputStream;
/*    */ import java.io.IOException;
/*    */ import java.io.InputStream;
/*    */ import java.net.URL;
/*    */ import tools.HexTool;
/*    */ import tools.Pair;
/*    */ import tools.Randomizer;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class LieDetectorScript
/*    */ {
/* 20 */   private static final String IMG_DIRECTORY = ServerConfig.WORLD_SCRIPTSPATH + "/lieDetector";
/*    */   private static final String CAPTCHA_VERIFIER = "98818D40B83AECCFB7AFD7FD9653E1037519AC61";
/*    */   private static final String CAPTCHA_SERVER = "http://localhost/captcha.php?verify=98818D40B83AECCFB7AFD7FD9653E1037519AC61";
/*    */   
/*    */   public static Pair<String, String> getImageBytes() {
/*    */     try {
/* 26 */       URL url = new URL("http://localhost/captcha.php?verify=98818D40B83AECCFB7AFD7FD9653E1037519AC61");
/*    */       
/* 28 */       InputStream inputStream = url.openStream();
/* 29 */       ByteArrayOutputStream output = new ByteArrayOutputStream();
/* 30 */       byte[] buffer = new byte[1024];
/* 31 */       int n = 0;
/* 32 */       while (-1 != (n = inputStream.read(buffer))) {
/* 33 */         output.write(buffer, 0, n);
/*    */       }
/* 35 */       String imgByte = HexTool.toString(output.toByteArray());
/* 36 */       return new Pair(imgByte.substring(39, imgByte.length()), output.toString().split("CAPTCHA")[0]);
/* 37 */     } catch (IOException ex) {
/* 38 */       File directory = new File(IMG_DIRECTORY);
/* 39 */       if (!directory.exists()) {
/* 40 */         System.err.println("lieDetector folder does not exist!");
/* 41 */         return null;
/*    */       } 
/* 43 */       String[] filename = directory.list();
/* 44 */       String answer = filename[Randomizer.nextInt(filename.length)];
/* 45 */       answer = answer.substring(0, answer.length() - 4);
/*    */       try {
/* 47 */         return new Pair(HexTool.toString(getBytesFromFile(new File(IMG_DIRECTORY + "/" + answer + ".jpg"))), answer);
/* 48 */       } catch (IOException e) {
/* 49 */         return null;
/*    */       } 
/*    */     } 
/*    */   }
/*    */   
/*    */   public static byte[] getBytesFromFile(File file) throws IOException {
/*    */     byte[] bytes;
/*    */     try {
/* 57 */       InputStream is = new FileInputStream(file);
/* 58 */       long length = file.length();
/* 59 */       if (length > 2147483647L) {
/* 60 */         is.close();
/* 61 */         return null;
/*    */       } 
/* 63 */       bytes = new byte[(int)length];
/* 64 */       int offset = 0;
/* 65 */       int numRead = 0;
/* 66 */       while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
/* 67 */         offset += numRead;
/*    */       }
/* 69 */       is.close();
/* 70 */       if (offset < bytes.length) {
/* 71 */         System.err.println("[Lie Detector Script] Could not completely read file " + file.getName());
/* 72 */         return null;
/*    */       } 
/* 74 */     } catch (IOException e) {
/* 75 */       return null;
/*    */     } 
/* 77 */     return bytes;
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\scripting\lieDetector\LieDetectorScript.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */